package com.bankcrm.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.bankcrm.dao.UserDao;
import com.bankcrm.model.User;
import com.opensymphony.xwork2.ActionSupport;

@Component
public class UserAction extends ActionSupport {

	private User user; //injection
	private UserDao userDao; // injection
	private int userId; 
	private List<User> usersList;
	
	public String addUser() {
		userDao.insertUser(user); 
		return SUCCESS;
	}
	
	public String deleteUser() {
		userDao.deleteUserById(userId); 
		return SUCCESS; 
	}
	
	public String getUserById() {
		user = userDao.getUserById(userId); 
		return SUCCESS;
	}
	
	public String updateUser() {
		userDao.updateUser(user); 
		return SUCCESS;
	}

	public String displayAllUsers() {
		usersList = userDao.getAllUsers(); 
		System.out.println(usersList.get(0).getUsername()); 
		return SUCCESS;
	}

	public User getUser() {
		return user;
	}
	public UserDao getUserDao() {
		return userDao;
	} 
	
	public int getUserId() {
		return userId;
	}
	
	public List<User> getUsersList() {
		return usersList;
	}

	@Resource
	public void setUser(User user) {
		this.user = user;
	}

	@Resource
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	
	public void setUserId(int userId) {
		this.userId = userId;
	}

	public void setUsersList(List<User> usersList) {
		this.usersList = usersList;
	}

}
